package com.apes.fn.scm.retailOrder.service.retailProcess.process;

import com.apes.fn.scm.retailOrder.model.RetailOrder;
import com.apes.fn.scm.retailOrder.service.retailProcess.CommonRetailDataProcess;
import com.apes.fn.scm.retailOrder.service.retailProcess.ServerAndLossQuotationProcess;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 收款方式调整
 *
 * @Author wuq
 * @Date 2021-7-28
 */
@Service
public class PaymentUpdateProcess extends CommonRetailDataProcess {

    @Override
    public void beforeSave(RetailOrder retailOrder) {
        beforeProcess(retailOrder, this::update);
    }

    private void update(RetailOrder retailOrder) {
        retailOrder.getPaymentMethodSet().forEach(paymentMethod -> {
            // 01 现金  02 银行卡  03 转账  04 支票  07 支付宝门店  08 微信门店  13 支付宝APP 14 微信APP  42 长沙微信 43 长沙微信冲红
            // 102 银联微信
            List<Object> list = Arrays.asList("01", "02", "03", "04","07", "08", "13", "14", "42", "43", "102");
            if (!list.contains(paymentMethod.getPaymentMethodType().getId())) {
                throw new RuntimeException(String.format("收款方式 [%s] 不允许做收款方式调整", paymentMethod.getPaymentMethodType().getName()));
            }
        });
        retailOrder.setScene(null);
        retailOrder.setPostDate(new Date());
    }

    @Override
    public void afterSave(RetailOrder retailOrder) {

    }

    @Override
    public boolean support(String orderType) {
        return "paymentUpdate".equals(orderType);
    }
}
